package cn.dada.dadarecipes.user.order.controller;

import cn.dada.dadarecipes.base.response.JsonResult;
import cn.dada.dadarecipes.user.order.pojo.dto.OrderPayDto;
import cn.dada.dadarecipes.user.order.pojo.dto.OrderUpdateParam;
import cn.dada.dadarecipes.user.order.pojo.dto.QueryOrderParam;
import cn.dada.dadarecipes.user.order.pojo.vo.OrderVO;
import cn.dada.dadarecipes.user.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "01.03订单模块")
@Slf4j
@RestController
@RequestMapping("/v1/user")
public class OrderController {
    @Autowired
    OrderService orderService;

    @ApiOperation(value = "查询订单功能")
    @GetMapping("/queryOrderParam")
    public JsonResult queryOrders(QueryOrderParam queryOrderParam) {
        log.debug("查询订单: queryOrderParam={}",queryOrderParam);
        List<OrderVO> orderVOs = orderService.queryOrders(queryOrderParam);
        return JsonResult.ok(orderVOs);
    }
    @ApiOperation(value = "订单更新功能")
    @PostMapping("/updateOrder")
    public JsonResult update(OrderUpdateParam orderUpdateParam) {
        log.debug("订单更新:orderVO={}", orderUpdateParam);
        orderService.update(orderUpdateParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "订单删除功能")
    @PostMapping("/deleteOrder/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("订单删除:id={}", id);
        orderService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "查询选中订单")
    @GetMapping("/select/order/checked/{userId}")
    public JsonResult selectOrderChecked(@PathVariable("userId") Long userId) {
        List<OrderVO> list = orderService.selectOrderChecked(userId);
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "订单支付功能")
    @PostMapping("/payOrder")
    public JsonResult payOrder(OrderPayDto orderpayDto) {
        orderService.payOrder(orderpayDto);
        return JsonResult.ok();
    }

}
